<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<script type="text/javascript" language="javascript">
    var combothajaranStorePayRek = createStore(false, 'mcombothajaranStorePayRek',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var semesterstorePayRek =createArrayStore([['I','Ganjil'],['II','Genap']]);
    var combo_bulan_StorePayRek=createArrayStore2( ['num', 'name'],bulan_data);
    var combo_bulan_StorePayRekB=createArrayStore2( ['num', 'name'],bulan_data);
    var comboKelasStorePayRek = createStore(false, 'mcomboKelasStorePayRek', ['kd_kelas','keterangan'], '<?php echo base_url(); ?>' + 'masterkelas/get_rows_combo');
    var rekeningstorePayRek = createStore(false, 'mrekeningstorePayRek', ['no_rek','keterangan'], '<?php echo base_url(); ?>' + 'masterrekening/get_rows_combo');
    
    var baseUrlPayRek='base_report/paymentrekap_print?idthajaran=';
    var printUrlPayRek='';
    defineTabFormDynamis(
    {
        name:'MyTabRekapPembayaranPiutang',
        xtype:'TabTabRekapPembayaranPiutang',
        alias:'widget.TabRekapPembayaranPiutang',
        title:'Rekap Pembayaran Piutang',
        id:'tab19'
        ,items:[
            {
                xtype: 'form',
                autoShow: true,
                id: 'panelpayrek',
                region: 'north',
                margins: '5 5 5 5',
                layout: 'column',                
                items:[
                    {
                        xtype: 'form',
                        columnWidth: .3,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 85,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype:'combo',
                                afterLabelTextTpl: required_css,
                                name: 'id_th_ajaran',
                                id: 'payrek_id_th_ajaran',
                                fieldLabel: 'Tahun Ajaran',                                    
                                //                    labelWidth: 80,
                                emptyText: 'Tahun Ajaran'
                                ,mode:'local',
                                store: combothajaranStorePayRek,
                                valueField: 'id_th_ajaran',
                                displayField: 'tahun_ajaran',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false  ,
                                hiddenName:'id_th_ajaran'
                                ,listeners:{
                                    select:function(cmb,rec){
                                        console.log(rec[0].get('tahun_ajaran'));
                                    }
                                }
                            },
                            {
                                xtype: 'combo',                                                            
                                //                                tooltip: 'Field tidak boleh kosong',
                                //                                afterLabelTextTpl: required_css,
                                fieldLabel: 'Semester',                        
                                id: 'payrek_semester',
                                mode:'local',
                                store: semesterstorePayRek,
                                valueField: 'mid',
                                displayField: 'mtext',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: true,
                                editable: false,                                
                                emptyText: 'Semester'    ,
                                name:'semester',
                                hiddenName:'semester'
                            },{
                                xtype:'fieldcontainer',
                                fieldLabel:'ThBl Periode',
                                //                    labelWidth: 130,
                                layout: 'hbox',                    
                                defaultType: 'textfield',                    
                                //                    margin: '0 0 5 0',
                                defaults: {
                                    labelWidth: 80,
                                    labelAlign: 'right'
                                    ,hideLabel: 'true'
                                },
                                //                        tooltip: 'Field tidak boleh kosong',
                                //                        afterLabelTextTpl: required_css,
                                items: [
                                    {
                                        xtype:'numberfield',
                                        name:'tahun',
                                        fieldLabel:'Tahun',
                                        id: 'payrek_tahun_p',
                                        emptyText:'Tahun',
                                        allowBlank: true,                                                                        
                                        //                            hideTrigger: true,
                                        fieldStyle: 'text-align: right;',
                                        minValue: new Date().getFullYear()
                                        ,flex:1
                                    },
                                    {
                                        xtype: 'combobox',
                                        name: 'bulan',
                                        id: 'payrek_bulan_p',
                                        displayField: 'name',
                                        valueField: 'num',
                                        queryMode: 'local',
                                        emptyText: 'Bulan',
                                        hiddenName:'bulan',
                                        //                            margins: '0 6 0 0',
                                        store: combo_bulan_StorePayRek,
                                        width: 100,
                                        allowBlank: true,
                                        forceSelection: true
                                        ,flex:1
                                    }
                                ]
                            }  
                        ]
                    },{
                        xtype: 'form',
                        columnWidth: .3,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 90,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype:'fieldcontainer',
                                fieldLabel:'Tanggal Bayar',
                                //                    labelWidth: 130,
                                layout: 'hbox',                    
                                defaultType: 'datefield',                    
                                //                    margin: '0 0 5 0',
                                defaults: {
                                    labelWidth: 90,
                                    labelAlign: 'right'
                                    ,hideLabel: 'true'
                                },
                                //                        tooltip: 'Field tidak boleh kosong',
                                //                        afterLabelTextTpl: required_css,
                                items: [ {
                                        xtype: 'datefield',
                                        name: 'tgl_awal',
                                        allowBlank: true, 
                                        vtype:'daterange',
                                        endDateField: 'payrek_tgl_akhir',
                                        afterLabelTextTpl: required_css,
                                        fieldLabel: 'Tanggal Awal',
                                        format:'d M Y',
                                        anchor: '90%'
                                        ,id:'payrek_tgl_awal'
                                        ,flex:1
                                        ,emptyText:'Awal'
                                    },
                                    {
                                        xtype: 'datefield',
                                        name: 'tgl_akhir',
                                        allowBlank: true, 
                                        vtype:'daterange',                                
                                        startDateField:  'payrek_tgl_awal',
                                        afterLabelTextTpl: required_css,
                                        fieldLabel: 'Tanggal Akhir',
                                        anchor: '90%',
                                        format:'d M Y'
                                        ,id:'payrek_tgl_akhir'
                                        ,flex:1
                                        ,emptyText:'Akhir'
                                    }
                                ]
                            }
                            ,{
                                xtype:'fieldcontainer',
                                fieldLabel:'ThBl Bayar',
                                //                    labelWidth: 130,
                                layout: 'hbox',                    
                                defaultType: 'textfield',                    
                                //                    margin: '0 0 5 0',
                                defaults: {
                                    labelWidth: 80,
                                    labelAlign: 'left'
                                    ,hideLabel: 'true'
                                },
                                //                        tooltip: 'Field tidak boleh kosong',
                                //                        afterLabelTextTpl: required_css,
                                items: [
                                    {
                                        xtype:'numberfield',
                                        name:'tahunb',
                                        fieldLabel:'Tahun',
                                        id: 'payrek_tahun_b',
                                        emptyText:'Tahun',
                                        allowBlank: true,                                                                        
                                        //                            hideTrigger: true,
                                        fieldStyle: 'text-align: right;',
                                        minValue: new Date().getFullYear()
                                        ,flex:1
                                    },
                                    {
                                        xtype: 'combobox',
                                        name: 'bulanb',
                                        id: 'payrek_bulan_b',
                                        displayField: 'name',
                                        valueField: 'num',
                                        queryMode: 'local',
                                        emptyText: 'Bulan',
                                        hiddenName:'bulan',
                                        //                            margins: '0 6 0 0',
                                        store: combo_bulan_StorePayB,
                                        width: 100,
                                        allowBlank: true,
                                        forceSelection: true
                                        ,flex:1
                                    }
                                ]
                            },
                            {
                                xtype: 'combo',                                                            
                                //                                tooltip: 'Field tidak boleh kosong',
                                //                                afterLabelTextTpl: required_css,
                                fieldLabel: 'No.Rekening',                        
                                id: 'payrek_rekening',
                                mode:'local',
                                store: rekeningstorePayRek,
                                valueField: 'no_rek',
                                displayField: 'no_rek',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: true,
                                editable: false,                                
                                emptyText: 'Rekening'    ,
                                name:'rekening',
                                hiddenName:'rekening'
                            }
                        ]
                    },{
                        xtype: 'form',
                        columnWidth: .4,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 140,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            ,{
                                xtype: 'radiogroup',
                                cls: 'x-check-group-alt',
                                hideLabel:false,
                                margins: '0 0 0 10',
                                border: 1,
                                flex:1,
                                allowBlank: false,
                                fieldLabel: 'Pengelompokan Laporan',
                                id:'payrek_groupby',name:'groupby',
                                
                                columns: [110, 110],
                                items: [
                                    {boxLabel: 'Rekening', name: 'groupby', inputValue: 'rekening', checked: true},
                                    {boxLabel: 'Jenis Biaya', name: 'groupby', inputValue: 'jenis'},
                                    {boxLabel: 'Tanggal Bayar', name: 'groupby', inputValue: 'tglbayar'},
                                    {boxLabel: 'ThBl Bayar', name: 'groupby', inputValue: 'thblbayar'},
                                    {boxLabel: 'ThBl Periode', name: 'groupby', inputValue: 'thbl'}
                                        
                                ]
                            }
                        ]
                    }
                ],
                tbar:[
                    {
                        xtype: 'button',
                        id:'btn_payrek_reset',
                        text: 'Reset',
                        iconCls: 'icon-refresh',
                        onClick: function(btn){
                            getComp('panelpayrek').getForm().reset();
                            //                            var frm1=getComp('panelpay').getForm().getValues();
                            //                            readLog(frm1.id_th_ajaran);
                        }
                    }
                ]
                ,bbar:
                [
                    {
                        xtype: 'button',
                        id:'btn_payrek_detail',
                        text: 'Tampilkan',
                        iconCls: 'icon-preview_report',
                        onClick: function(btn){
                            if(!getComp('panelpayrek').getForm().isValid()){
                                set_message(1, 'Pilihan Tidak Valid!!!');
                                return;
                            }else{
                                var frmvalue=getComp('panelpayrek').getForm().getValues();
                                if(!frmvalue.id_th_ajaran){
                                    set_message(1, 'Tahun Ajaran Belum Diisi!!');
                                    return;
                                }else{
                                    printUrlPayRek=baseUrlPayRek;
                                    printUrlPayRek +=frmvalue.id_th_ajaran;
                                    printUrlPayRek +='&thajaran=' + getComp('payrek_id_th_ajaran').getRawValue() ;
                                    
                                }
                                if(frmvalue.semester){
                                    printUrlPayRek +='&idsemester=' + frmvalue.semester ;
                                    printUrlPayRek +='&semester=' + getComp('payrek_semester').getRawValue() ; ;
                                }
                                if(frmvalue.tahun && frmvalue.bulan){
                                    var thbl=setThbl(frmvalue.tahun, frmvalue.bulan);
                                    printUrlPayRek +='&thblp=' + thbl ;
                                    
                                }
                                
                                if(frmvalue.tgl_awal){
                                    readLog(frmvalue.tgl_awal);
                                    printUrlPayRek +='&tglawal=' + format_date(new Date(frmvalue.tgl_awal), 'Y-m-d')  ;
                                }
                                if(frmvalue.tgl_akhir){
                                    printUrlPayRek +='&tglakhir=' + format_date(new Date(frmvalue.tgl_akhir), 'Y-m-d') ;
                                }
                                if(frmvalue.tahunb && frmvalue.bulanb){
                                    var thbl=setThbl(frmvalue.tahunb, frmvalue.bulanb);
                                    printUrlPayRek +='&thblb=' + thbl ;
                                    
                                }
                                 if(frmvalue.rekening){
                                    printUrlPayRek +='&rekening=' + frmvalue.rekening ;                                    
                                }
                                
                                if(frmvalue.groupby){
                                    printUrlPayRek +='&groupby=' + frmvalue.groupby ;                                    
                                }
//                                readLog(format_date(new Date(frmvalue.tgl_akhir), 'Y-m-d'));
                                readLog(printUrlPayRek);
//                                return;
                                to_print('printpayrek', printUrlPayRek);
                                
                            }
                                                        
                        }                       
                        
                    }
//                    ,{
//                        xtype: 'button',
//                        id:'btn_payrek_rekap',
//                        text: 'Tampilkan Rekap',
//                        iconCls: 'icon-preview_report',
//                        onClick: function(btn){
//                            getComp('panelpayrek').getForm().reset();
//                            //                            var frm1=getComp('panelpay').getForm().getValues();
//                            //                            readLog(frm1.id_th_ajaran);
//                        }
//                    }
                ]
            },{
                
                xtype: 'panel',
                autoShow: true,
                autoScroll: true,
                enableToggle: true,
                title:'Print Preview PDF',
                id: 'panelpayrek_c',
                region: 'center',
                margins: '0 5 5 5',
                layout: 'fit',                
                tools: [{
                        type: 'maximize',
                        tooltip: 'Maximize Print Preview' 
                        ,listeners:{
                            click:function()   {
                                if(printUrlPayRek){
                                    var winprintpayrek=Ext.create('winprint2');
                                    winprintpayrek.maximize();
                                    to_print('printoutpdf2', printUrlPayRek); 
                                }
                                //                                                                
                                                                
                                                                                        
                            }
                        }
                    }],
                html:'<iframe style="width:100%;height:100%;" id="printpayrek" src=""></iframe>'
                
            }
        ]
    },function(){
        
    }
);
</script>